package com.sudichina.sudichina.view.activity.orlder;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sudichina.sudichina.Contains;
import com.sudichina.sudichina.R;
import com.sudichina.sudichina.adapter.OrlderAdapter;
import com.sudichina.sudichina.view.activity.login.LoginActivity;
import com.sudichina.sudichina.view.activity.main.BaseActivity;
import com.sudichina.sudichina.view.fragment.AllFragment;
import com.sudichina.sudichina.view.fragment.AppearFragment;
import com.sudichina.sudichina.view.fragment.BaseFragemnt;
import com.sudichina.sudichina.view.fragment.FinishFragment;
import com.sudichina.sudichina.view.fragment.HearFragment;
import com.sudichina.sudichina.view.fragment.UnfinishFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyOrlderActivity extends BaseActivity {


    @BindView(R.id.tl_title)
    TabLayout privateTlTitle;
    @BindView(R.id.vp)
    ViewPager privateVp;
    @BindView(R.id.activity_main)
    LinearLayout privateActivityMain;
    @BindView(R.id.dingdan_iv_back)
    ImageView privateDingdanIvBack;

    private ArrayList<BaseFragemnt> myorlder_list_fragments;
    private AllFragment allFragment;
    private AppearFragment appearFragment;
    private HearFragment hearFragment;
    private UnfinishFragment unfinshFragment;
    private FinishFragment finishFragment;
    private ArrayList<String> list_title;
    private OrlderAdapter orlderAdapter;

    //adb connect 192.168.0.111:5555
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myorlder);
        ButterKnife.bind(this);

        //检测是否登录
        LoginActivity.startMeAndInitIsLogin(this,Contains.MYORLDER_EXTRA);



    }

    @Override
    protected void onResume() {
        super.onResume();


        initData();
        orlderAdapter = new OrlderAdapter(getSupportFragmentManager(), myorlder_list_fragments);

        //viewpager加载adapter
        privateVp.setAdapter(orlderAdapter);
        //关联指示器
        privateTlTitle.setupWithViewPager(privateVp);
    }

    private void initData() {
        //初始化 fragment
//全部订单
        allFragment = new AllFragment();
        //申诉维权
        appearFragment = new AppearFragment();
        //审理中
        hearFragment = new HearFragment();
        //未完成
        unfinshFragment = new UnfinishFragment();
        //已经完成
        finishFragment = new FinishFragment();

        //将fragment装进列表中
        myorlder_list_fragments = new ArrayList<>();
        myorlder_list_fragments.add(allFragment);
        myorlder_list_fragments.add(hearFragment);
        myorlder_list_fragments.add(unfinshFragment);
        myorlder_list_fragments.add(finishFragment);
        myorlder_list_fragments.add(appearFragment);

        //为TabLayout添加名称
        for (int i = 0; i < myorlder_list_fragments.size(); i++) {
            privateTlTitle.addTab(privateTlTitle.newTab().setText(myorlder_list_fragments.get(i).getTitle()));
        }


    }

    @OnClick(R.id.dingdan_iv_back)
    public void onClick() {


        finish();
    }


}

